PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/google/code/magja/model/product/ProductAttribute.java

http://magja.googlecode.com/
Java | 707 lines | 409 code | 92 blank | 206 comment | 186 complexity | 9f1da61c95d1a63a7fe59b8766a5a9f4 MD5 | raw file
  1. /**
  2. * @author andre
  3. *
  4. */
  5. package com.google.code.magja.model.product;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import java.util.Map;
  9. import com.google.code.magja.model.BaseMagentoModel;
  10. public class ProductAttribute extends BaseMagentoModel {
  11. private static final long serialVersionUID=7015962673006863327L;
  12. public enum Scope {
  13. STORE(0), GLOBAL(1), WEBSITE(2);
  14. private final Integer value;
  15. private Scope(Integer value) {
  16. this.value = value;
  17. }
  18. public Integer getValue() {
  19. return value;
  20. }
  21. public static Scope getByName(String name) {
  22. if (name.equals("store"))
  23. return STORE;
  24. else if (name.equals("global"))
  25. return GLOBAL;
  26. else if (name.equals("website"))
  27. return WEBSITE;
  28. return null;
  29. }
  30. }
  31. private Scope scope = Scope.GLOBAL;
  32. private String code;
  33. private String group;
  34. private String type;
  35. private String backend;
  36. private String frontend;
  37. private String label;
  38. private String input;
  39. private String attributeClass;
  40. private String source;
  41. private String defaultValue;
  42. private Boolean visible;
  43. private Boolean required;
  44. private Boolean userDefined;
  45. private Boolean searchable;
  46. private Boolean filterable;
  47. private Boolean comparable;
  48. private Boolean visibleOnFront;
  49. private Boolean visibleInAdvancedSearch;
  50. private Boolean unique;
  51. private List<ProductType> applyTo;
  52. private Map<Integer, String> options;
  53. private Boolean sortBy;
  54. private Boolean configurable;
  55. /*
  56. * (non-Javadoc)
  57. *
  58. * @see com.google.code.magja.model.BaseMagentoModel#serializeToApi()
  59. */
  60. @Override
  61. public Object serializeToApi() {
  62. Map<String, Object> properties = getAllProperties();
  63. List<Object> list = new LinkedList<Object>();
  64. list.add(code);
  65. /*
  66. * When list the attributes, the type property its the input, and when
  67. * it save a attribute, the type property means varchar, int, etc, and
  68. * the input is text, textarea, select, etc. so, we have to work
  69. * workaround that here, thats because we didnt put the input mapping on
  70. * the mapping file
  71. */
  72. if (input != null)
  73. properties.put("input", input);
  74. if (type != null)
  75. properties.put("type", type);
  76. /*
  77. * we have to workaround the scope too, in the api the scope its the
  78. * 'global' property
  79. */
  80. properties.put("global", scope.ordinal());
  81. // not necessary
  82. properties.remove("code");
  83. properties.remove("attribute_id");
  84. // handle the applyTo
  85. if (applyTo != null) {
  86. if (!applyTo.isEmpty()) {
  87. String[] types = new String[applyTo.size()];
  88. int i = 0;
  89. for (ProductType type : applyTo)
  90. types[i++] = type.getType();
  91. }
  92. }
  93. // finally, add the properties to parameters to create
  94. list.add(properties);
  95. return list;
  96. }
  97. /**
  98. * @return the scope
  99. */
  100. public Scope getScope() {
  101. return scope;
  102. }
  103. /**
  104. * @param scope
  105. * the scope to set
  106. */
  107. public void setScope(Scope scope) {
  108. this.scope = scope;
  109. }
  110. /**
  111. * @return the code
  112. */
  113. public String getCode() {
  114. return code;
  115. }
  116. /**
  117. * @param code
  118. * the code to set
  119. */
  120. public void setCode(String code) {
  121. this.code = code;
  122. }
  123. /**
  124. * @return the group
  125. */
  126. public String getGroup() {
  127. return group;
  128. }
  129. /**
  130. * @param group
  131. * the group to set
  132. */
  133. public void setGroup(String group) {
  134. this.group = group;
  135. }
  136. /**
  137. * @return the type
  138. */
  139. public String getType() {
  140. return type;
  141. }
  142. /**
  143. * @param type
  144. * the type to set
  145. */
  146. public void setType(String type) {
  147. this.type = type;
  148. }
  149. /**
  150. * @return the backend
  151. */
  152. public String getBackend() {
  153. return backend;
  154. }
  155. /**
  156. * @param backend
  157. * the backend to set
  158. */
  159. public void setBackend(String backend) {
  160. this.backend = backend;
  161. }
  162. /**
  163. * @return the frontend
  164. */
  165. public String getFrontend() {
  166. return frontend;
  167. }
  168. /**
  169. * @param frontend
  170. * the frontend to set
  171. */
  172. public void setFrontend(String frontend) {
  173. this.frontend = frontend;
  174. }
  175. /**
  176. * @return the label
  177. */
  178. public String getLabel() {
  179. return label;
  180. }
  181. /**
  182. * @param label
  183. * the label to set
  184. */
  185. public void setLabel(String label) {
  186. this.label = label;
  187. }
  188. /**
  189. * @return the input
  190. */
  191. public String getInput() {
  192. return input;
  193. }
  194. /**
  195. * @param input
  196. * the input to set
  197. */
  198. public void setInput(String input) {
  199. this.input = input;
  200. }
  201. /**
  202. * @return the attributeClass
  203. */
  204. public String getAttributeClass() {
  205. return attributeClass;
  206. }
  207. /**
  208. * @param attributeClass
  209. * the attributeClass to set
  210. */
  211. public void setAttributeClass(String attributeClass) {
  212. this.attributeClass = attributeClass;
  213. }
  214. /**
  215. * @return the source
  216. */
  217. public String getSource() {
  218. return source;
  219. }
  220. /**
  221. * @param source
  222. * the source to set
  223. */
  224. public void setSource(String source) {
  225. this.source = source;
  226. }
  227. /**
  228. * @return the defaultValue
  229. */
  230. public String getDefaultValue() {
  231. return defaultValue;
  232. }
  233. /**
  234. * @param defaultValue
  235. * the defaultValue to set
  236. */
  237. public void setDefaultValue(String defaultValue) {
  238. this.defaultValue = defaultValue;
  239. }
  240. /**
  241. * @return the visible
  242. */
  243. public Boolean getVisible() {
  244. return visible;
  245. }
  246. /**
  247. * @param visible
  248. * the visible to set
  249. */
  250. public void setVisible(Boolean visible) {
  251. this.visible = visible;
  252. }
  253. /**
  254. * @return the required
  255. */
  256. public Boolean getRequired() {
  257. return required;
  258. }
  259. /**
  260. * @param required
  261. * the required to set
  262. */
  263. public void setRequired(Boolean required) {
  264. this.required = required;
  265. }
  266. /**
  267. * @return the userDefined
  268. */
  269. public Boolean getUserDefined() {
  270. return userDefined;
  271. }
  272. /**
  273. * @param userDefined
  274. * the userDefined to set
  275. */
  276. public void setUserDefined(Boolean userDefined) {
  277. this.userDefined = userDefined;
  278. }
  279. /**
  280. * @return the searchable
  281. */
  282. public Boolean getSearchable() {
  283. return searchable;
  284. }
  285. /**
  286. * @param searchable
  287. * the searchable to set
  288. */
  289. public void setSearchable(Boolean searchable) {
  290. this.searchable = searchable;
  291. }
  292. /**
  293. * @return the filterable
  294. */
  295. public Boolean getFilterable() {
  296. return filterable;
  297. }
  298. /**
  299. * @param filterable
  300. * the filterable to set
  301. */
  302. public void setFilterable(Boolean filterable) {
  303. this.filterable = filterable;
  304. }
  305. /**
  306. * @return the comparable
  307. */
  308. public Boolean getComparable() {
  309. return comparable;
  310. }
  311. /**
  312. * @param comparable
  313. * the comparable to set
  314. */
  315. public void setComparable(Boolean comparable) {
  316. this.comparable = comparable;
  317. }
  318. /**
  319. * @return the visibleOnFront
  320. */
  321. public Boolean getVisibleOnFront() {
  322. return visibleOnFront;
  323. }
  324. /**
  325. * @param visibleOnFront
  326. * the visibleOnFront to set
  327. */
  328. public void setVisibleOnFront(Boolean visibleOnFront) {
  329. this.visibleOnFront = visibleOnFront;
  330. }
  331. /**
  332. * @return the visibleInAdvancedSearch
  333. */
  334. public Boolean getVisibleInAdvancedSearch() {
  335. return visibleInAdvancedSearch;
  336. }
  337. /**
  338. * @param visibleInAdvancedSearch
  339. * the visibleInAdvancedSearch to set
  340. */
  341. public void setVisibleInAdvancedSearch(Boolean visibleInAdvancedSearch) {
  342. this.visibleInAdvancedSearch = visibleInAdvancedSearch;
  343. }
  344. /**
  345. * @return the unique
  346. */
  347. public Boolean getUnique() {
  348. return unique;
  349. }
  350. /**
  351. * @param unique
  352. * the unique to set
  353. */
  354. public void setUnique(Boolean unique) {
  355. this.unique = unique;
  356. }
  357. /**
  358. * @return the applyTo
  359. */
  360. public List<ProductType> getApplyTo() {
  361. return applyTo;
  362. }
  363. /**
  364. * @param applyTo
  365. * the applyTo to set
  366. */
  367. public void setApplyTo(List<ProductType> applyTo) {
  368. this.applyTo = applyTo;
  369. }
  370. /**
  371. * @return the options
  372. */
  373. public Map<Integer, String> getOptions() {
  374. return options;
  375. }
  376. /**
  377. * @param options
  378. * the options to set
  379. */
  380. public void setOptions(Map<Integer, String> options) {
  381. this.options = options;
  382. }
  383. /**
  384. * @return the sortBy
  385. */
  386. public Boolean getSortBy() {
  387. return sortBy;
  388. }
  389. /**
  390. * @param sortBy
  391. * Used for sorting in product listing
  392. */
  393. public void setSortBy(Boolean sortBy) {
  394. this.sortBy = sortBy;
  395. }
  396. /**
  397. * @return the configurable
  398. */
  399. public Boolean getConfigurable() {
  400. return configurable;
  401. }
  402. /**
  403. * @param configurable
  404. * the configurable to set
  405. */
  406. public void setConfigurable(Boolean configurable) {
  407. this.configurable = configurable;
  408. }
  409. /*
  410. * (non-Javadoc)
  411. *
  412. * @see java.lang.Object#hashCode()
  413. */
  414. @Override
  415. public int hashCode() {
  416. final int prime = 31;
  417. int result = super.hashCode();
  418. result = prime * result + ((applyTo == null) ? 0 : applyTo.hashCode());
  419. result = prime * result
  420. + ((attributeClass == null) ? 0 : attributeClass.hashCode());
  421. result = prime * result + ((backend == null) ? 0 : backend.hashCode());
  422. result = prime * result + ((code == null) ? 0 : code.hashCode());
  423. result = prime * result
  424. + ((comparable == null) ? 0 : comparable.hashCode());
  425. result = prime * result
  426. + ((configurable == null) ? 0 : configurable.hashCode());
  427. result = prime * result
  428. + ((defaultValue == null) ? 0 : defaultValue.hashCode());
  429. result = prime * result
  430. + ((filterable == null) ? 0 : filterable.hashCode());
  431. result = prime * result
  432. + ((frontend == null) ? 0 : frontend.hashCode());
  433. result = prime * result + ((group == null) ? 0 : group.hashCode());
  434. result = prime * result + ((input == null) ? 0 : input.hashCode());
  435. result = prime * result + ((label == null) ? 0 : label.hashCode());
  436. result = prime * result + ((options == null) ? 0 : options.hashCode());
  437. result = prime * result
  438. + ((required == null) ? 0 : required.hashCode());
  439. result = prime * result + ((scope == null) ? 0 : scope.hashCode());
  440. result = prime * result
  441. + ((searchable == null) ? 0 : searchable.hashCode());
  442. result = prime * result + ((sortBy == null) ? 0 : sortBy.hashCode());
  443. result = prime * result + ((source == null) ? 0 : source.hashCode());
  444. result = prime * result + ((type == null) ? 0 : type.hashCode());
  445. result = prime * result + ((unique == null) ? 0 : unique.hashCode());
  446. result = prime * result
  447. + ((userDefined == null) ? 0 : userDefined.hashCode());
  448. result = prime * result + ((visible == null) ? 0 : visible.hashCode());
  449. result = prime
  450. * result
  451. + ((visibleInAdvancedSearch == null) ? 0
  452. : visibleInAdvancedSearch.hashCode());
  453. result = prime * result
  454. + ((visibleOnFront == null) ? 0 : visibleOnFront.hashCode());
  455. return result;
  456. }
  457. /*
  458. * (non-Javadoc)
  459. *
  460. * @see java.lang.Object#equals(java.lang.Object)
  461. */
  462. @Override
  463. public boolean equals(Object obj) {
  464. if (this == obj)
  465. return true;
  466. if (!super.equals(obj))
  467. return false;
  468. if (getClass() != obj.getClass())
  469. return false;
  470. ProductAttribute other = (ProductAttribute) obj;
  471. if (applyTo == null) {
  472. if (other.applyTo != null)
  473. return false;
  474. } else if (!applyTo.equals(other.applyTo))
  475. return false;
  476. if (attributeClass == null) {
  477. if (other.attributeClass != null)
  478. return false;
  479. } else if (!attributeClass.equals(other.attributeClass))
  480. return false;
  481. if (backend == null) {
  482. if (other.backend != null)
  483. return false;
  484. } else if (!backend.equals(other.backend))
  485. return false;
  486. if (code == null) {
  487. if (other.code != null)
  488. return false;
  489. } else if (!code.equals(other.code))
  490. return false;
  491. if (comparable == null) {
  492. if (other.comparable != null)
  493. return false;
  494. } else if (!comparable.equals(other.comparable))
  495. return false;
  496. if (defaultValue == null) {
  497. if (other.defaultValue != null)
  498. return false;
  499. } else if (!defaultValue.equals(other.defaultValue))
  500. return false;
  501. if (filterable == null) {
  502. if (other.filterable != null)
  503. return false;
  504. } else if (!filterable.equals(other.filterable))
  505. return false;
  506. if (frontend == null) {
  507. if (other.frontend != null)
  508. return false;
  509. } else if (!frontend.equals(other.frontend))
  510. return false;
  511. if (group == null) {
  512. if (other.group != null)
  513. return false;
  514. } else if (!group.equals(other.group))
  515. return false;
  516. if (input == null) {
  517. if (other.input != null)
  518. return false;
  519. } else if (!input.equals(other.input))
  520. return false;
  521. if (label == null) {
  522. if (other.label != null)
  523. return false;
  524. } else if (!label.equals(other.label))
  525. return false;
  526. if (options == null) {
  527. if (other.options != null)
  528. return false;
  529. } else if (!options.equals(other.options))
  530. return false;
  531. if (required == null) {
  532. if (other.required != null)
  533. return false;
  534. } else if (!required.equals(other.required))
  535. return false;
  536. if (scope == null) {
  537. if (other.scope != null)
  538. return false;
  539. } else if (!scope.equals(other.scope))
  540. return false;
  541. if (searchable == null) {
  542. if (other.searchable != null)
  543. return false;
  544. } else if (!searchable.equals(other.searchable))
  545. return false;
  546. if (sortBy == null) {
  547. if (other.sortBy != null)
  548. return false;
  549. } else if (!sortBy.equals(other.sortBy))
  550. return false;
  551. if (source == null) {
  552. if (other.source != null)
  553. return false;
  554. } else if (!source.equals(other.source))
  555. return false;
  556. if (type == null) {
  557. if (other.type != null)
  558. return false;
  559. } else if (!type.equals(other.type))
  560. return false;
  561. if (unique == null) {
  562. if (other.unique != null)
  563. return false;
  564. } else if (!unique.equals(other.unique))
  565. return false;
  566. if (userDefined == null) {
  567. if (other.userDefined != null)
  568. return false;
  569. } else if (!userDefined.equals(other.userDefined))
  570. return false;
  571. if (visible == null) {
  572. if (other.visible != null)
  573. return false;
  574. } else if (!visible.equals(other.visible))
  575. return false;
  576. if (visibleInAdvancedSearch == null) {
  577. if (other.visibleInAdvancedSearch != null)
  578. return false;
  579. } else if (!visibleInAdvancedSearch
  580. .equals(other.visibleInAdvancedSearch))
  581. return false;
  582. if (visibleOnFront == null) {
  583. if (other.visibleOnFront != null)
  584. return false;
  585. } else if (!visibleOnFront.equals(other.visibleOnFront))
  586. return false;
  587. if (configurable == null) {
  588. if (other.configurable != null)
  589. return false;
  590. } else if (!configurable.equals(other.configurable))
  591. return false;
  592. return true;
  593. }
  594. /*
  595. * (non-Javadoc)
  596. *
  597. * @see java.lang.Object#toString()
  598. */
  599. @Override
  600. public String toString() {
  601. return "ProductAttribute [applyTo=" + applyTo + ", attributeClass="
  602. + attributeClass + ", backend=" + backend + ", code=" + code
  603. + ", comparable=" + comparable + ", defaultValue="
  604. + defaultValue + ", filterable=" + filterable + ", frontend="
  605. + frontend + ", group=" + group + ", input=" + input
  606. + ", label=" + label + ", options=" + options + ", required="
  607. + required + ", scope=" + scope + ", searchable=" + searchable
  608. + ", sortBy=" + sortBy + ", source=" + source + ", type="
  609. + type + ", unique=" + unique + ", userDefined=" + userDefined
  610. + ", visible=" + visible + ", visibleInAdvancedSearch="
  611. + visibleInAdvancedSearch + ", visibleOnFront="
  612. + visibleOnFront + ", configurable=" + configurable + ", id="
  613. + id + ", properties=" + properties + "]";
  614. }
  615. }