Package fr.openwide.maven.artifact.notifier.core.business.artifact.model

Examples of fr.openwide.maven.artifact.notifier.core.business.artifact.model.Artifact


          @Override
          public void onClick(AjaxRequestTarget target) {
            try {
              Project project = ProjectArtifactsPanel.this.getModelObject();
              Artifact artifact = getModelObject();
             
              projectService.removeArtifact(project, artifact);
              Session.get().success(getString("project.description.artifacts.remove.success"));
            } catch (Exception e) {
              LOGGER.error("Error occured while removing artifact", e);
              Session.get().error(getString("project.description.artifacts.remove.error"));
            }
            target.add(getPage());
            FeedbackUtils.refreshFeedback(target, getPage());
          }
         
          @Override
          protected void onConfigure() {
            super.onConfigure();
            setVisible(MavenArtifactNotifierSession.get().hasRoleAdmin());
          }
        }.add(new AuthenticatedOnlyBehavior()));
      }
    };
    add(artifactListView);
   
    add(new WebMarkupContainer("emptyList") {
      private static final long serialVersionUID = 6700720373087584498L;

      @Override
      public void onConfigure() {
        super.onConfigure();
        setVisible(artifactListView.size() <= 0);
      }
    });
   
    // Add artifact form
    IModel<Artifact> emptyArtifactModel = new GenericEntityModel<Long, Artifact>(null);
   
    final ArtifactDropDownChoice artifactDropDown = new ArtifactDropDownChoice("artifact", emptyArtifactModel,
        new ProjectArtifactSelect2AjaxAdapter(ArtifactDropDownChoice.CHOICE_RENDERER));
    artifactDropDown.setWidth(DropDownChoiceWidth.NORMAL);
    artifactDropDown.setRequired(true);
    artifactDropDown.setLabel(new ResourceModel("project.description.artifacts.chooseOne"));
    artifactDropDown.add(new LabelPlaceholderBehavior());
    artifactDropDown.add(new AuthenticatedOnlyBehavior());
   
    final Form<Artifact> addArtifactForm = new StatelessForm<Artifact>("addArtifactForm", emptyArtifactModel) {
      private static final long serialVersionUID = 1L;

      @Override
      protected void onConfigure() {
        super.onConfigure();
        setVisible(MavenArtifactNotifierSession.get().hasRoleAdmin());
      }
    };
    addArtifactForm.add(artifactDropDown);
    addArtifactForm.add(new AjaxSubmitLink("addArtifactLink", addArtifactForm) {
      private static final long serialVersionUID = 1L;

      @Override
      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        Project project = ProjectArtifactsPanel.this.getModelObject();
        Artifact selectedArtifact = artifactDropDown.getModelObject();
       
        if (selectedArtifact != null) {
          if (selectedArtifact.getProject() == null) {
            try {
              projectService.addArtifact(project, selectedArtifact);
              getSession().success(getString("project.description.artifacts.add.success"));
            } catch (Exception e) {
              LOGGER.error("Unknown error occured while adding an artifact to a project", e);
View Full Code Here


 
  @Override
  public Artifact getOrCreate(ArtifactKey artifactKey) throws ServiceException, SecurityServiceException {
    ArtifactGroup artifactGroup = artifactGroupService.getOrCreate(artifactKey.getGroupId());
   
    Artifact artifact = getByArtifactKey(artifactKey);
    if (artifact == null) {
      artifact = new Artifact(artifactKey.getArtifactId());
      artifactGroup.addArtifact(artifact);
      create(artifact);
    }
   
    return artifact;
View Full Code Here

  @Override
  protected void addItemColumns(final Item<Artifact> item, IModel<? extends Artifact> itemModel) {
    item.setOutputMarkupId(true);
   
    Artifact artifact = item.getModelObject();
    final IModel<Artifact> artifactModel = new ArtifactModel(Model.of(item.getModelObject().getArtifactKey()));
    final ArtifactLastVersionModel artifactLastVersionModel = new ArtifactLastVersionModel(artifactModel);
   
    item.add(new ClassAttributeAppender(new LoadableDetachableModel<String>() {
      private static final long serialVersionUID = 1L;
     
      @Override
      protected String load() {
        User user = MavenArtifactNotifierSession.get().getUser();
        boolean isFollowed = user != null && userService.isFollowedArtifact(user, item.getModelObject());
        boolean isDeprecated = artifactModel.getObject() != null &&
            ArtifactDeprecationStatus.DEPRECATED.equals(artifactModel.getObject().getDeprecationStatus());
        return isFollowed ? "success" : (isDeprecated ? "warning" : null);
      }
    }));
   
    // GroupId column
    item.add(new Label("groupId", BindingModel.of(artifactModel, Binding.artifact().group().groupId())));
    item.add(new ExternalLink("groupLink", mavenCentralSearchUrlService.getGroupUrl(artifact.getGroup().getGroupId())));

    // ArtifactId column
    Link<Void> localArtifactLink = ArtifactDescriptionPage.linkDescriptor(artifactModel).link("localArtifactLink");
    localArtifactLink.add(new Label("artifactId", BindingModel.of(artifactModel, Binding.artifact().artifactId())));
    item.add(localArtifactLink);
   
    item.add(new ExternalLink("artifactLink", mavenCentralSearchUrlService.getArtifactUrl(artifact.getGroup().getGroupId(), artifact.getArtifactId())));
   
    // LastVersion, lastUpdateDate columns
    item.add(new Label("synchronizationPlannedPlaceholder", new ResourceModel("artifact.follow.synchronizationPlanned")) {
      private static final long serialVersionUID = 1L;

      @Override
      protected void onConfigure() {
        super.onConfigure();
        setVisible(artifactModel.getObject() != null && !artifactLastVersionModel.isLastVersionAvailable());
      }
    });
   
    WebMarkupContainer localContainer = new WebMarkupContainer("followedArtifact") {
      private static final long serialVersionUID = 1L;

      @Override
      protected void onConfigure() {
        super.onConfigure();
        setVisible(artifactLastVersionModel.isLastVersionAvailable());
      }
    };
    localContainer.add(new ArtifactVersionTagPanel("latestVersion", Model.of(artifactLastVersionModel.getLastVersion())));
    String latestVersion = (artifact.getLatestVersion() != null ? artifact.getLatestVersion().getVersion() : "");
    localContainer.add(new ExternalLink("versionLink", mavenCentralSearchUrlService.getVersionUrl(artifact.getGroup().getGroupId(),
        artifact.getArtifactId(), latestVersion)));
   
    localContainer.add(new DateLabelWithPlaceholder("lastUpdateDate",
        Model.of(artifactLastVersionModel.getLastVersionUpdateDate()), DatePattern.SHORT_DATE));
    item.add(localContainer);
View Full Code Here

          private static final long serialVersionUID = -5179621361619239269L;
         
          @Override
          public void onClick(AjaxRequestTarget target) {
            try {
              Artifact artifact = ArtifactFollowersPanel.this.getModelObject();
              User user = getModelObject();
             
              if (userService.unfollowArtifact(user, artifact)) {
                Session.get().success(getString("administration.artifact.followers.delete.success"));
              } else {
                getSession().warn(getString("artifact.delete.notFollowed"));
              }
            } catch (Exception e) {
              LOGGER.error("Error occured while unfollowing artifact", e);
              Session.get().error(getString("administration.artifact.followers.delete.error"));
            }
            target.add(getPage());
            FeedbackUtils.refreshFeedback(target, getPage());
          }
        });
      }
    };
    add(followersListView);
   
    add(new WebMarkupContainer("emptyList") {
      private static final long serialVersionUID = 6700720373087584498L;

      @Override
      public void onConfigure() {
        super.onConfigure();
        setVisible(followersListView.size() <= 0);
      }
    });
   
    // Add member form
    IModel<User> emptyUserModel = new GenericEntityModel<Long, User>(null);
   
    final UserAutocompleteAjaxComponent userAutocomplete = new UserAutocompleteAjaxComponent("userAutocomplete",
        emptyUserModel);
    userAutocomplete.setAutoUpdate(true);
   
    final Form<User> addMemberForm = new Form<User>("addFollowerForm", emptyUserModel);
    addMemberForm.add(userAutocomplete);
    addMemberForm.add(new AjaxSubmitLink("addFollowerLink", addMemberForm) {
      private static final long serialVersionUID = 6935376642872117563L;
     
      @Override
      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        Artifact artifact = ArtifactFollowersPanel.this.getModelObject();
        User selectedUser = userAutocomplete.getModelObject();
       
        if (selectedUser != null) {
          try {
            userService.followArtifact(selectedUser, artifact);
View Full Code Here

    relatedArtifactLink.add(new Label("relatedArtifact", new LoadableDetachableModel<String>() {
      private static final long serialVersionUID = 1L;

      @Override
      protected String load() {
        Artifact relatedArtifact = relatedArtifactModel.getObject();
        if (relatedArtifact != null) {
          return relatedArtifact.getArtifactKey().getKey();
        }
        return null;
      }
    }));
    relatedArtifactContainer.add(relatedArtifactLink);
View Full Code Here

      }
     
      @Override
      protected void onConfigure() {
        super.onConfigure();
        Artifact artifact = getModelObject();
        User user = MavenArtifactNotifierSession.get().getUser();
        boolean isDeprecated = artifact == null || ArtifactDeprecationStatus.DEPRECATED.equals(artifact.getDeprecationStatus());
       
        setVisible(!isDeprecated && user != null && !userService.isFollowedArtifact(user, artifact));
      }
    };
    follow.add(new AuthenticatedOnlyBehavior());
    add(follow);
   
    // Deprecated
    final IModel<Artifact> relatedArtifactModel = BindingModel.of(getModel(), Binding.artifact().relatedArtifact());
    Link<Void> relatedArtifactLink = ArtifactDescriptionPage.linkDescriptor(relatedArtifactModel).link("deprecated");
    relatedArtifactLink.add(new Behavior() {
      private static final long serialVersionUID = 1L;

      @Override
      public void onConfigure(Component component) {
        super.onConfigure(component);
        Artifact artifact = ArtifactFollowActionsPanel.this.getModelObject();
        User user = MavenArtifactNotifierSession.get().getUser();
        boolean isDeprecated = artifact != null && ArtifactDeprecationStatus.DEPRECATED.equals(artifact.getDeprecationStatus());
       
        component.setVisibilityAllowed(isDeprecated && user != null && !userService.isFollowedArtifact(user, artifact));
        component.setEnabled(relatedArtifactModel.getObject() != null);
      }
    });
    relatedArtifactLink.add(new AuthenticatedOnlyBehavior());
    relatedArtifactLink.add(new AttributeModifier("title", new LoadableDetachableModel<String>() {
      private static final long serialVersionUID = 1L;

      @Override
      protected String load() {
        Artifact relatedArtifact = relatedArtifactModel.getObject();
        StringBuilder sb = new StringBuilder(getString("artifact.description.deprecated"));
        if (relatedArtifact != null) {
          sb.append(" ").append(getString("artifact.deprecation.link.title", relatedArtifactModel));
        }
        return sb.toString();
      }
    }));
    add(relatedArtifactLink);
   
    // Unfollow
    AjaxLink<Artifact> unfollow = new AjaxLink<Artifact>("unfollow", getModel()) {
      private static final long serialVersionUID = 1L;
     
      @Override
      public void onClick(AjaxRequestTarget target) {
        try {
          if (!userService.unfollowArtifact(MavenArtifactNotifierSession.get().getUser(), getModelObject())) {
            getSession().warn(getString("artifact.delete.notFollowed"));
          }
          refresh(target);
        } catch (Exception e) {
          LOGGER.error("Error occured while unfollowing artifact", e);
          getSession().error(getString("common.error.unexpected"));
        }
        FeedbackUtils.refreshFeedback(target, getPage());
      }
     
      @Override
      protected void onConfigure() {
        super.onConfigure();
        Artifact artifact = getModelObject();
        User user = MavenArtifactNotifierSession.get().getUser();
       
        setVisible(user != null && artifact != null && userService.isFollowedArtifact(user, artifact));
      }
    };
View Full Code Here

      }
     
      @Override
      protected void onConfigure() {
        super.onConfigure();
        Artifact artifact = getModelObject();
        User user = MavenArtifactNotifierSession.get().getUser();
        boolean isDeprecated = artifact == null || ArtifactDeprecationStatus.DEPRECATED.equals(artifact.getDeprecationStatus());
       
        setVisible(!isDeprecated && user != null && !userService.isFollowedArtifact(user, artifact));
      }
    };
    follow.add(new AuthenticatedOnlyBehavior());
    add(follow);
   
    // Unfollow
    AjaxLink<Artifact> unfollow = new AjaxLink<Artifact>("unfollow", artifactModel) {
      private static final long serialVersionUID = 1L;
     
      @Override
      public void onClick(AjaxRequestTarget target) {
        try {
          if (!userService.unfollowArtifact(MavenArtifactNotifierSession.get().getUser(), getModelObject())) {
            getSession().warn(getString("artifact.delete.notFollowed"));
          }
          target.add(getPage());
        } catch (Exception e) {
          LOGGER.error("Error occured while unfollowing artifact", e);
          getSession().error(getString("common.error.unexpected"));
        }
        FeedbackUtils.refreshFeedback(target, getPage());
      }
     
      @Override
      protected void onConfigure() {
        super.onConfigure();
        Artifact artifact = getModelObject();
        User user = MavenArtifactNotifierSession.get().getUser();
       
        setVisible(user != null && artifact != null && userService.isFollowedArtifact(user, artifact));
      }
    };
    unfollow.add(new AuthenticatedOnlyBehavior());
    add(unfollow);
   
    // Followers count label
    add(new CountLabel("followersCountLabel", "artifact.description.followers", new LoadableDetachableModel<Long>() {
      private static final long serialVersionUID = 1L;

      @Override
      protected Long load() {
        Artifact artifact = artifactModel.getObject();
        return artifact != null ? artifact.getFollowersCount() : 0;
      }
    }));
   
    add(new DeprecatedArtifactPanel("deprecated", artifactModel));
   
View Full Code Here

    add(new ExternalLink("groupLink", new LoadableDetachableModel<String>() {
      private static final long serialVersionUID = 1L;
     
      @Override
      protected String load() {
        Artifact artifact = ArtifactDescriptionPanel.this.getModelObject();
        return mavenCentralSearchUrlService.getGroupUrl(artifact.getGroup().getGroupId());
      }
    }));
   
    // ArtifactID
    add(new Label("artifactId", BindingModel.of(getModel(), Binding.artifact().artifactId())));
    add(new ExternalLink("artifactLink", new LoadableDetachableModel<String>() {
      private static final long serialVersionUID = 1L;
     
      @Override
      protected String load() {
        Artifact artifact = ArtifactDescriptionPanel.this.getModelObject();
        return mavenCentralSearchUrlService.getArtifactUrl(artifact.getGroup().getGroupId(), artifact.getArtifactId());
      }
    }));
   
    // Deprecation popup
    ArtifactDeprecationFormPopupPanel deprecationPopup = new ArtifactDeprecationFormPopupPanel("deprecationPopup", artifactModel);
View Full Code Here

    return followedArtifact;
  }
 
  @Override
  public FollowedArtifact followArtifactBean(User user, ArtifactBean artifactBean) throws ServiceException, SecurityServiceException {
    Artifact artifact = artifactService.getOrCreate(artifactBean.getArtifactKey());
   
    return followArtifact(user, artifact);
  }
View Full Code Here

    }
  }
 
  @Override
  public boolean unfollowArtifact(User user, FollowedArtifact followedArtifact) throws ServiceException, SecurityServiceException {
    Artifact artifact = followedArtifact.getArtifact();
    artifact.setFollowersCount(Math.max(0, artifact.getFollowersCount() - 1));
   
    user.getFollowedArtifacts().remove(followedArtifact);
    update(user);
   
    followedArtifactService.delete(followedArtifact);
View Full Code Here

TOP

Related Classes of fr.openwide.maven.artifact.notifier.core.business.artifact.model.Artifact

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.